package com.hsd.znsh.vlc;

import lombok.Getter;

import java.io.*;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-27 15:42:42
 */
@Getter
public class VlcThread extends Thread {

    private Process process;

    private String rtsp;

    private String sout;

    public VlcThread(String rtsp, String sout) {
        this.rtsp = rtsp;
        this.sout = sout;
    }

    @Override
    public void run() {
        String os=System.getProperty("os.name").toLowerCase();
        String vlcCmdString;
        if(os.startsWith("win")){
            vlcCmdString= "D:/VLC/vlc.exe vlc -vvv " + rtsp +
                    " :sout=#transcode{vcodec=theo,vb=800,acodec=vorb,ab=128,channels=2,samplerate=44100}" +
                    ":http{mux=ogg,dst=" + sout + "} :no-sout-all :sout-keep";
        }else{
            vlcCmdString="vlc -vvv "+rtsp+
                    " :sout=#transcode{vcodec=theo,vb=800,acodec=vorb,ab=128,channels=2,samplerate=44100}"+
                    ":http{mux=ogg,dst="+ sout +"} :no-sout-all :sout-keep";
        }
        String[] cmdLine = vlcCmdString.split(" ");
        System.out.println(vlcCmdString);
        ProcessBuilder processBuilder = new ProcessBuilder(cmdLine);
        try {
            this.process = processBuilder.start();
            InputStream inputStream = process.getErrorStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                //System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
